package ca.ulaval.ift.gloo.SimSolution.presentation;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

public class DisplayGridPanel extends JPanel implements MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2103412260469268332L;
	private Grid grid;
	private Reseau reseau;
	private Point pointClicked;
	
	public DisplayGridPanel(Grid grid, Reseau reseau) {
		this.grid = grid;
		this.reseau = reseau;
		
		// On ajoute un MouseListener pour capturer les clicks de souris
		addMouseListener(this);
        
        //this.repaint();
	}
	
	public DisplayGridPanel() {
		this.grid = new Grid(800, 800, 2);
		this.reseau = new Reseau();
		this.pointClicked = new Point(0,0);
		// On ajoute un MouseListener pour capturer les clicks de souris
		addMouseListener(this);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		grid.paintGrid(g);
		reseau.drawNode(pointClicked, g);
		//g.drawRoundRect(pt.x , pt.y, 5, 5, 0, 0);
		//g.drawRoundRect(pt2.x , pt2.y, 5, 5, 0, 0);

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		//On récupére les coordonnées de l'endroit où il y a eu un click
		pointClicked = e.getPoint();
		grid.getGridPoint(pointClicked);
		repaint();
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	
	
}
